package com.chahu.mapper;

import com.chahu.entity.User;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserMapper {

    @Select("select * from users where username = #{username} and password = #{password}")
    User getUser(@Param("username") String username, @Param("password") String password);
    
    @Select("select role from users where username = #{arg0} and password = #{arg1}")
    int login(String name, String pwd);

    @Insert("insert into users values(null, #{nickname}, #{username}, #{password}, #{phone}, #{role})")
    void registerUser(User user);

    @Select("select * from users limit #{arg0}, #{arg1}")
    List<User> getUserList(int page, int pageSize);
    
    @Update("update users set nickname=#{nickname}, password=#{password}, phone=#{phone} where id = #{id}")
    void updateById(User user);
    
    @Delete("delete from users where id = #{arg0}")
    void deleteById(int id);
}
